package com.taotao.manage.service;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.github.abel533.entity.Example;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.taotao.manage.pojo.Item;
import com.taotao.manage.pojo.ItemDesc;
import com.taotao.manage.pojo.ItemWithCat;
@Service
public class ItemService extends BaseService<Item>{
	@Autowired
	private ItemDescService itemDescService;
	
	public void insertItemAndItemDesc(Item item,String desc){
		//初始化商品状态,1为正常
		item.setStatus(1);
		//强制设置id为null
		item.setId(null);
		super.saveSelective(item);
		//封装ItemDesc
		ItemDesc record = new ItemDesc();
		record.setItemId(item.getId());
		//保存商品详细信息
		record.setItemDesc(desc);
		this.itemDescService.saveSelective(record);
	}
	
	public boolean updateItemAndItemDesc(Item item,String desc){
		if (item.getId()==null) {
			return false;
		}
		//不初始化商品状态
		item.setStatus(null);
		//更新item
		Integer count1 = super.updateSelective(item);
		//封装itemDesc
		ItemDesc itemDesc = new ItemDesc();
		itemDesc.setItemId(item.getId());
		itemDesc.setItemDesc(desc);
		//更新商品详情
		Integer count2 = itemDescService.updateSelective(itemDesc);
		return count1==1&&count2==1;
		
	}
}
